package com.sysd.mail.smtp.command;

import com.sysd.mail.config.ServerConfig;
import com.sysd.mail.entity.bean.Email;
import com.sysd.mail.smtp.SmtpSession;
import com.sysd.mail.util.EmailUtils;

import java.io.IOException;

/**
 * project: mail
 *
 * @author bsh
 * @description MailCommand
 * @dataTime 2023/3/28 15:03
 * @company 丽水信阳软件科技有限公司
 */
public class MailCommand extends BaseSmtpCommand {
    public MailCommand() {
        super("MAIL");
    }

    /**
     * 执行命令
     *
     * @param command     命令名称
     * @param smtpSession smtp session
     * @return smtp session
     * @throws IOException io exception
     */
    @Override
    public SmtpSession execute(String command, SmtpSession smtpSession) throws IOException {
        String args=this.getCommandName(command);
        String emailAddress = EmailUtils.extractEmailAddress(args.trim(), 5);
        smtpSession.write("250 Requested mail action okay, completed!\r\n");
        smtpSession.setMailTransactionInProcess(true);
        Email emailModel =smtpSession.getEmail();
        emailModel.setFrom(emailAddress);
        smtpSession.setEmail(emailModel);
        return smtpSession;
    }
}
